<template>
  <div>
    <table-ext :columns="columns2" :searchForm="searchForm2" :config="config2" ref="tableExt2">
      <template slot="table-action">
          <el-button type="info" @click="addExpert">新增</el-button>
      </template>
    </table-ext>
  </div>

</template>
<script>
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    // 引入自定义表格组件
    components:{
      'table-ext': TableExt
    },
    data() {
      return {
        // 弹框属性
        addOrUpdateForm: {
          abolishReason: ''
        },
        // 弹框显示控制
        dialogFormVisible: false,
        // 修改弹框控制
        dialogUpdate: false,    
        config2:{ 
          title: 'RFI', //页面标题
          isPage: true, //是否分页
          isNo: true, //是否显示序号
          selection: false, //是否显示复选框
          crudMapping:{ // CRUD方法
            query:{
              url: this.lib.config.host.vendorMgt + '/vendormgt/vsp/rfiitem/query',
              method: 'securityPost'
            },
            delete: {
              url: this.lib.config.host.vendorMgt + '/vendormgt/vsp/rfi/delete',
              method: 'securityPost'
            }
          }
        },
        
         // 查询表单配置
        searchForm2:[{ // 查询表单配置
          label: '采购组织', 
          key: 'purOrgId', 
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/'+this.getCurrUserId(),
            method:'get',
            label:'purOrgName',
            value:'id'
          }
        }, {
          label: '采购组',
          key: 'purGroupId',
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/{purOrgId}',
            method:'post',
            label:'purGroupName',
            value:'id'
          }
        },{
          label: 'RFI编码',
          key: 'rfiCode',
          type: 'input'
        },{
          label: '标题',
          key: 'rfiTitle',
          type: 'input'
        },{
          label: '供应商名称',
          key: 'vendorName',
          type: 'input'
        },{
          label: '类型',
          key: 'infoType',
          type: 'select',
          dict: [{
            value: 'rfi2',
            label: '产品认证'
          },{
            value: 'rfi3',
            label: '调查问卷'
          }]
        },{
          label: '审核状态',
          key: 'checkStatus',
          type: 'select',
          dict: [
          {
            value: '1',
            label: '已审核'
          }, {
            value: '0',
            label: '未审核'
          },
          {
            value: '-1',
            label: '驳回'
          },
          {
            value: '3',
            label: '待审核'
          }
          ]
        },{
          label: '反馈状态',
          key: 'feedbackStatus',
          type: 'select',
          dict: [
          {
            value: '1',
            label: '已反馈'
          }, {
            value: '0',
            label: '未反馈'
          },
          {
            value: '2',
            label: '部分反馈'
          }
          ]
        }],
        
        columns2:[{ 
          label: '操作', // 表格header
          width: '90',
          render:(createElement, params)=>{ // 动态渲染，click事件示例
            let _this = this;
            if(params.row.checkStatus == 3){
              return createElement('div', {}, 
                [createElement('el-button', {
                    props: {
                      type: 'text',
                    },
                    on: {
                      click() {
                        _this.toCheck(params.row.id,params.row.rfiId);
                      }
                    }
                  }, '审核')
                ]);
            }else if(params.row.feedbackStatus == 1){
               return createElement('div', {}, 
                [createElement('el-button', {
                    props: {
                      type: 'text',
                    },
                    on: {
                      click() {
                        _this.toView(params.row.id,params.row.rfiId);
                      }
                    }
                  }, '查看')
                ]);
            }else{
              return createElement('div', '--');
            }
          }
        },{
          label: 'RFI编码',
          key: 'rfi.rfiCode',
          width: '160'
        },{
          label: '采购组织',
          key: 'rfi.purOrgName',
          width: '160'
        },{
          label: '采购组',
          key: 'rfi.purGroupName',
          width: '120'
        },{
          label: '标题',
          key: 'rfi.title',
          width: '200'
        },{
          label: 'RFI类型',
          key: 'rfi.infoTypeName',
          width: '130'
        },{
          label: '供应商',
          key: 'vendorName',
          width: '220'
        },{
          label: '反馈状态',
          key: 'feedbackStatus',
          width: '90',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.feedbackStatus,
                titles: [{status:0,title:'未反馈'},{status:1,title:'已反馈'}]
            }});
          }
        },{
          label: '反馈人',
          key: 'feedbackUserName',
          width:'160'
        },{
          label: '反馈日期',
          key: 'feedbackTime',
          width:'110'
        },{
          label: '审核状态',
          key: 'checkStatus',
          width:'110',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.checkStatus,
                titles: [{status:0,title:'未审核'},{status:1,title:'已审核'},{status:3,title:'待审核'},{status:-1,title:'驳回'}]
            }});
          }
        }
        ]
      };
    },
    created(){
      if(this.$route.query){
        this.config.crudMapping.query.data=this.$route.query
      }
    },
    mounted() {
    },
    methods: {
      // 新增专家
      addExpert(){
        this.dialogUpdate = false;
        this.dialogFormVisible = true;
        this.$nextTick(()=>{
          this.resetForm('addOrUpdateForm');
        });
      },
      toView(id,rfiId) {
         this.$router.push('/Index/Supplier/common/RfiItemView?id='+ id + '&'+'rfiId' + '=' + rfiId);
      },
      toCheck(id,rfiId){
        this.$router.push('/Index/Supplier/common/RfiItemCheck?id='+ id + '&'+'rfiId' + '=' + rfiId);
      }
    }
  }
</script>
